package com.skycong.hello77.activity.common.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.text.Spanned;
import android.util.DisplayMetrics;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.skycong.hello77.R;

/**
 * Created by Kiki on 2018/5/22.
 */

public class MyDialog extends Dialog {
    private TextView tv_title;//标题
    private TextView tv_message;//警告提示
    private Button   btn_confirm;//确认按钮
    private Button   btn_cancel;//取消
    private Context context;
    public MyDialog(Context context) {
        super(context);
        setContentView(R.layout.layout_notifition);
        tv_title = (TextView) findViewById(R.id.tv_title_dialog);
        tv_message = (TextView) findViewById(R.id.tv_message);
        btn_cancel = (Button) findViewById(R.id.btn_cancel_commoncanceldialog);
        btn_confirm = (Button) findViewById(R.id.btn_confirm_commoncanceldialog);
        setDialogWidth(context);
    }

    private void setDialogWidth(Context dialogWidth) {
        Window win = getWindow();
        WindowManager.LayoutParams lp = win.getAttributes();
        win.getDecorView().setPadding(0, 0, 0, 0);

        /** 获取屏幕的宽和高 */
        DisplayMetrics dm = new DisplayMetrics();
        Activity activity = (Activity) context;
        activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
        lp.width = dm.widthPixels * 8 / 10;
        win.setAttributes(lp);
    }
    /**
     * 设置标题
     * @param title
     */
    public void setHead(String title){
        tv_title.setText(title);
    }
    /**
     * 设置警告提示
     * @param message
     */
    public void setMessage(String message){
        tv_message.setText(message);
    }

    /**
     * 设置警告提示
     * @param message
     */
    public void setMessage(Spanned message){
        tv_message.setText(message);
    }

    /**
     * 设置确定按钮
     * @param btntext
     * @param listener
     */
    public void setPositiveButton(String btntext, android.view.View.OnClickListener listener){
        btn_confirm.setText(btntext);
        btn_confirm.setOnClickListener(listener);
    }

    /**
     * 确定按钮文字颜色
     * @param color
     */
    public void setPositiveButtonTxtColor(int color){
        btn_confirm.setTextColor(color);
    }

    /**
     * 设置取消按钮
     * @param btntext
     * @param listener
     */
    public void setNegativeButton(String btntext, android.view.View.OnClickListener listener){
        btn_cancel.setText(btntext);
        btn_cancel.setOnClickListener(listener);
    }
    /**
     * dialog显示
     */
    public void display() {
        show();
    }
}
